﻿using Authorization.Center.Controllers;
using Authorization.Center.Dto;
using Authorization.Center.SqlServer;
using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Common.helper;
using S.Transplantation.Api.Application.Command;
using S.Transplantation.Domain.Models;
using S.Transplantation.Infrastructure.InterFace;
using S.Transplantation.Read.Api.Dto;

namespace S.Transplantation.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class TransplantationController : BaseController
    {
        private readonly IMapper mapper;
        private readonly IMediator mediator;
        private readonly IDescendantTransfertRepository DTRepository;
       

        public TransplantationController(IMediator mediator, IDescendantTransfertRepository DTRepository, IMapper mapper, MySqlDbContext db):base(db)
        {
            this.mapper = mapper;
            this.mediator = mediator;
            this.DTRepository = DTRepository;
          
        }
        /// <summary>
        /// 批量修改转种信息
        /// </summary>
        /// <param name="updateTransplantationListDtos"></param>
        /// <returns></returns>
        [HttpPost("UpdateTransplantationList")]
        public async Task<IActionResult> GetTransplantationList(List<TransplantationListDto> updateTransplantationListDtos)
        {
            foreach (var item in updateTransplantationListDtos)
            {
                item.UpdateBy = UserStrategyDto.UserTrueName;
                
            }
            var result = await mediator.Send(new UpdateTransplantationListCommand() { UpdatetransplantationListDtos = updateTransplantationListDtos });
            return Ok(result);
        }
      /// <summary>
      /// 批量添加转种信息
      /// </summary>
      /// <param name="addTransplantationListDtos"></param>
      /// <returns></returns>
        [HttpPost("AddTransplantation")]
        public async Task<IActionResult> AddTransplantation(List<TransplantationListDto> addTransplantationListDtos)
        {
            foreach (var item in addTransplantationListDtos)
            {
                item.CreateBy = UserStrategyDto.UserTrueName;
            }
            var result = await mediator.Send(new AddTransplantationListCommand() { AddtransplantationListDtos = addTransplantationListDtos });
            return Ok(result);
        }
        /// <summary>
        /// 批量删除转种信息
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>

        [HttpDelete("DeleteTransplantation")]
        public async Task<IActionResult> DeleteTransplantation(string ids)
        {
            var result = await mediator.Send(new DeleteTransplantationListCommand() { Ids = ids });
            return Ok(result);
        }
       
        [HttpGet("httpclient")]
        public IActionResult get()
        {
            return Ok(HttpClientHelper.GetResponse("https://10.31.56.9:7130/api/SheepFileModel/GetGeneRankEnu"));
        }
    }
}